﻿#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include "jthread.h"
#include "jfuturewatcher.h"
#include "jconcurrentmap.h"

// class ThreadTask

class ThreadTask : public JRunnable
{
public:
    explicit ThreadTask();
    ~ThreadTask();

    void stop();

    // JRunnable interface
public:
    void run();

private:
    bool q_running;
};

// class ThreadDialog

class QSpinBox;
class QPushButton;
class QLineEdit;

class ThreadDialog : public QDialog
{
    Q_OBJECT
public:
    explicit ThreadDialog(QWidget *parent = 0);
    ~ThreadDialog();

    void start();
    void stop();

public Q_SLOTS:
    void onThreadCountChanged(int value);
    void onButtonSwitchClicked();
#ifndef _MSC_VER
    void onTimeout();
#endif

private:
    QSpinBox *q_spinBoxThreadCount;
    QPushButton *q_buttonSwitch;
#ifdef __unix__
    QLineEdit* q_lineEditActiveThreadCount;
#endif
    QList<ThreadTask *> q_tasks;
};

#endif // DIALOG_H
